//
//  AutoCheckCell.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/27/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//


import UIKit
import SnapKit

final class AutoCheckCell: UITableViewCell {
    
    private lazy var hintLbl: UILabel = {
        let lbl = UILabel()
        lbl.font = .systemFont(ofSize: 14)
        lbl.textColor = .greyColor
        lbl.textAlignment = .left
        return lbl
    }()
    private lazy var valueLbl: UILabel = {
        let lbl = UILabel()
        lbl.font = .systemFont(ofSize: 14)
        lbl.textColor = .darkBlueColor
        return lbl
    }()
    
    private var bottomConstraint: Constraint?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        self.addViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public func setUpLastRow () {
        bottomConstraint?.deactivate()
        valueLbl.snp.makeConstraints { (make) in
            bottomConstraint = make.bottom.equalToSuperview().offset(-10).constraint
        }
    }
    
    private func addViews () {
        self.selectionStyle = .none
        contentView.addSubview(valueLbl)
        contentView.addSubview(hintLbl)
        
        hintLbl.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview().inset(10)
            make.top.equalToSuperview().inset(10)
        }
        valueLbl.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview().inset(10)
            make.top.equalTo(hintLbl.snp.bottom).offset(5)
            make.height.equalTo(20)
            bottomConstraint = make.bottom.equalToSuperview().offset(-6).constraint
        }
    }
}


extension AutoCheckCell: ConfigurableCell {
    
    func configure(data object: AutoCheckViewModel.AutoCheckCellItem?, index: Int) {
        if let _data = object {
            self.hintLbl.text = _data.hint
            self.valueLbl.text = _data.value
        }
    }
    
    func returnData() -> AutoCheckViewModel.AutoCheckCellItem? {
        return nil
    }
}
